//impacts of recession over parental income ventiles. And maybe ability, too.
import delimited "$dir/Model/simulated_data/simulated_data_base.csv", clear

//renaming
ren v1 theta
ren v2 e
ren v3 x
ren v4 a
ren v5 t
ren v6 p
ren v7 I
ren v8 H 
ren v9 tau
ren v10 s
ren v11 s_val
ren v12 prob_diff_I
ren v13 prob_diff_H
ren v14 l 
ren v15 m
ren v16 w
ren v17 tax
ren v18 c
ren v19 util
ren v20 switch
ren v21 gov_exp
ren v22 sim
ren v23 i_v


tab m if l == 1 & t == 18
tab m if l == 1 & t == 20 & e == 2
tab m if l == 1 & t == 22 & e == 3

//nix observations for kids who are in school
drop if t == 0 

//get lifetime wages and years worked for each individual simulation
preserve
collapse (sum) w l tax, by(i_v sim)
tempfile outcomes
ren w w_total
ren l l_total
ren tax tax_total
save `outcomes'
restore

merge m:1 i_v sim using `outcomes', keep(match) nogen

keep if t == 23 
gen enroll = (s>1)
gen hs = (e==1 & s==1)
gen drop = (e==1 & s>1)
gen sc = (e==2)
gen coll = (e==3)

su enroll hs drop sc coll w_total l_total tax_total

gen inc_dec = ceil(i_v / 2)


//weird stuff with d67
su tau I H if inc_dec == 1 | inc_dec == 2
tab s if inc_dec == 1 | inc_dec == 2
su tau if inc_dec == 1 | inc_dec == 2, d


su tau I H if inc_dec == 6 | inc_dec == 7
tab s if inc_dec == 6 | inc_dec == 7




//lifetime wages and years worked, average savings and educadtional attainment, by parent income ventile
collapse (mean) w_total l_total tax_total enroll hs drop sc coll gov_exp, by (inc_dec)
save "$temp/outcomes_base_pinc_dec", replace


//impacts of recession over parental income ventiles. And maybe ability, too.
import delimited "$dir/Model/simulated_data/simulated_data_rec.csv", clear

//renaming
ren v1 theta
ren v2 e
ren v3 x
ren v4 a
ren v5 t
ren v6 p
ren v7 I
ren v8 H 
ren v9 tau
ren v10 s
ren v11 s_val
ren v12 prob_diff_I
ren v13 prob_diff_H
ren v14 l 
ren v15 m
ren v16 w
ren v17 tax
ren v18 c
ren v19 util
ren v20 switch
ren v21 gov_exp
ren v22 sim
ren v23 i_v


tab m if l == 1 & t == 18
tab m if l == 1 & t == 20 & e == 2
tab m if l == 1 & t == 22 & e == 3


//nix observations for kids who are in school
drop if t == 0 

//get lifetime wages and years worked for each individual simulation
preserve
collapse (sum) w l tax, by(i_v sim)
tempfile outcomes
ren w w_total
ren l l_total
ren tax tax_total
save `outcomes'
restore

merge m:1 i_v sim using `outcomes', keep(match) nogen

keep if t == 23 
gen enroll = (s>1)
gen hs = (e==1 & s==1)
gen drop = (e==1 & s>1)
gen sc = (e==2)
gen coll = (e==3)

su enroll hs drop sc coll w_total l_total tax_total
gen inc_dec = ceil(i_v / 2)

//weird stuff with d67
su tau I H if inc_dec == 1 | inc_dec == 2
tab s if inc_dec == 1 | inc_dec == 2
su tau if inc_dec == 1 | inc_dec == 2, d

su tau I H if inc_dec == 6 | inc_dec == 7
tab s if inc_dec == 6 | inc_dec == 7





//lifetime wages and years worked, average savings and educadtional attainment, by parent income ventile
collapse (mean) w_total l_total tax_total enroll hs drop sc coll gov_exp, by (inc_dec)
ds inc_dec, not
foreach var in `r(varlist)'{
	ren `var' `var'_rec
}
save "$temp/outcomes_rec_pinc_dec", replace



//impacts of recession over parental income ventiles. And maybe ability, too.
import delimited "$dir/Model/simulated_data/simulated_data_rec_nopbr.csv", clear

//renaming
ren v1 theta
ren v2 e
ren v3 x
ren v4 a
ren v5 t
ren v6 p
ren v7 I
ren v8 H 
ren v9 tau
ren v10 s
ren v11 s_val
ren v12 prob_diff_I
ren v13 prob_diff_H
ren v14 l 
ren v15 m
ren v16 w
ren v17 tax
ren v18 c
ren v19 util
ren v20 switch
ren v21 gov_exp
ren v22 sim
ren v23 i_v


tab m if l == 1 & t == 18
tab m if l == 1 & t == 20 & e == 2
tab m if l == 1 & t == 22 & e == 3


//nix observations for kids who are in school
drop if t == 0 

//get lifetime wages and years worked for each individual simulation
preserve
collapse (sum) w l tax, by(i_v sim)
tempfile outcomes
ren w w_total
ren l l_total
ren tax tax_total
save `outcomes'
restore

merge m:1 i_v sim using `outcomes', keep(match) nogen

keep if t == 23 
gen enroll = (s>1)
gen hs = (e==1 & s==1)
gen drop = (e==1 & s>1)
gen sc = (e==2)
gen coll = (e==3)

su enroll hs drop sc coll w_total l_total tax_total
gen inc_dec = ceil(i_v / 2)

//weird stuff with d67
su tau I H if inc_dec == 1 | inc_dec == 2
tab s if inc_dec == 1 | inc_dec == 2
su tau if inc_dec == 1 | inc_dec == 2, d

//lifetime wages and years worked, average savings and educadtional attainment, by parent income ventile
collapse (mean) w_total l_total tax_total enroll hs drop sc coll gov_exp, by (inc_dec)
ds inc_dec, not
foreach var in `r(varlist)'{
	ren `var' `var'_rec_nopbr
}
save "$temp/outcomes_rec_pinc_dec_nopbr", replace


//get to work!
use "$temp/outcomes_base_pinc_dec", clear
merge 1:1 inc_dec using "$temp/outcomes_rec_pinc_dec", keep(match) nogen
merge 1:1 inc_dec using "$temp/outcomes_rec_pinc_dec_nopbr", keep(match) nogen

ds w_total l_total tax_total enroll hs drop sc coll gov_exp
foreach var in `r(varlist)'{
	gen `var'_delta_rec = `var'_rec - `var'
	gen `var'_delta_rec_nopbr = `var'_rec_nopbr - `var'

}

replace coll_delta_rec = coll_delta_rec * 100
replace enroll_delta_rec = enroll_delta_rec * 100
replace coll_delta_rec_nopbr = coll_delta_rec_nopbr * 100

su enroll enroll_rec if inc_dec==5
su hs hs_rec if inc_dec==5	
su drop drop_rec if inc_dec==5
su sc sc_rec if inc_dec==5
su coll coll_rec if inc_dec==5


//lifetime wage impacts in thousands of dollars
replace w_total_delta_rec = w_total_delta_rec * 40000
replace w_total_delta_rec = w_total_delta_rec / 1000

replace w_total_delta_rec_nopbr = w_total_delta_rec_nopbr * 40000
replace w_total_delta_rec_nopbr = w_total_delta_rec_nopbr / 1000
save "$temp/rec_impacts_baseline", replace


twoway connected coll_delta_rec inc_dec, ylabel(-5(2.5)10) yline(0) xlabel(1(1)10) ///
xtitle("Parent Income Decile") ytitle("Change in College Attainment (pp)") color(black) msize(medsmall) msymbol(circle)  ///
|| connected coll_delta_rec_nopbr inc_dec, legend(lab(1 "Baseline") lab(2 "No Parental Response")) lp(dash) color(black) msize(medsmall) msymbol(triangle)
graph export "$output/recession_impacts_coll.png", replace

twoway connected w_total_delta_rec inc_dec, xlabel(1(1)10) ylabel(-50(25)100) yline(0) ///
xtitle("Parent Income Decile") ytitle("Change in Lifetime Earnings ($1,000)") color(black) msize(medsmall) msymbol(circle) /// 
|| connected w_total_delta_rec_nopbr inc_dec, legend(lab(1 "Baseline") lab(2 "No Parental Response")) color(black) msize(medsmall) msymbol(triangle) lp(dash)
graph export "$output/recession_impacts_w.png", replace
graph close





//table of intensive-margin schooling adjustments



//impacts of recession over parental income ventiles. And maybe ability, too.
import delimited "$dir/Model/simulated_data/simulated_data_base.csv", clear

//renaming
ren v1 theta
ren v2 e
ren v3 x
ren v4 a
ren v5 t
ren v6 p
ren v7 I
ren v8 H 
ren v9 tau
ren v10 s
ren v11 s_val
ren v12 prob_diff_I
ren v13 prob_diff_H
ren v14 l 
ren v15 m
ren v16 w
ren v17 tax
ren v18 c
ren v19 util
ren v20 switch
ren v21 gov_exp
ren v22 sim
ren v23 i_v
keep if t == 65
gen uniqid = _n



keep uniqid s 
save "$temp/s_choices_baseline", replace


//impacts of recession over parental income ventiles. And maybe ability, too.
import delimited "$dir/Model/simulated_data/simulated_data_rec.csv", clear

//renaming
ren v1 theta
ren v2 e
ren v3 x
ren v4 a
ren v5 t
ren v6 p
ren v7 I
ren v8 H 
ren v9 tau
ren v10 s
ren v11 s_val
ren v12 prob_diff_I
ren v13 prob_diff_H
ren v14 l 
ren v15 m
ren v16 w
ren v17 tax
ren v18 c
ren v19 util
ren v20 switch
ren v21 gov_exp
ren v22 sim
ren v23 i_v
keep if t == 65
gen uniqid = _n


ren s s_rec
merge 1:1 uniqid using "$temp/s_choices_baseline", keep(match) nogen
tab s s_rec, row

//exit





